package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/13 22:03
 * @Version 1.0
 */

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;
import java.util.Vector;

/**解决arrayList线程不安全的问题*/
public class Thread0501 {
    public static void main(String[] args) {
        List<String> stringList =new Vector<>();
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                stringList.add(UUID.randomUUID().toString().substring(0,7));
                System.out.println(stringList);
            },String.valueOf(i)).start();
        }
    }
    /**使用Vector*/
    @Test
    public void  test(){
        List<String> stringList =new Vector<>();
        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                stringList.add(UUID.randomUUID().toString().substring(0,7));
                System.out.println(stringList);
            },String.valueOf(i)).start();
        }
    }
}
